require 'test/unit'
require 'src/authz'

class TC_Trans < Test::Unit::TestCase
  def test_empty_source_should_transfer_to_empty
    assert_equal('', transfer(''))
  end

  def test_comment_transfer_to_empty
    assert_equal('', transfer('#foo'))
  end

  def test_empty_dir_should_transfer_to_empty
    assert_equal('', transfer('[dir]'))
  end

  def test_empty_groups_should_transfer_to_empty
    assert_equal('', transfer('[groups]'))
  end

  def test_comment_dir_should_transfer_to_empty
    assert_equal('', transfer("[dir]\n#foo = bar"))
  end

  def test_single_user
    assert_equal('cvs chacl -R user:rwc dIr', transfer(<<-EOS
[dIr]
user = rwc
EOS
))
  end

  def test_two_users
    assert_equal("cvs chacl -R user1:rwc dIr\ncvs chacl -R user2:rwc dIr",
transfer(<<-EOS
[dIr]
user1 user2 = rwc
EOS
))
  end

  def test_single_group
    assert_equal("cvs chacl -R user1:rwc dIr\ncvs chacl -R user2:rwc dIr", transfer(<<-EOS
[groups]
group = user1 user2
[dIr]
@group = rwc
EOS
))
  end

  def test_wildcard_user
    assert_equal("cvs chacl -R user:rwc dIr", transfer(<<-EOS
[groups]
group = user
[dIr]
* = rwc
EOS
))
  end

  def test_empty_access_rights
    assert_equal('cvs chacl -R user:n dIr', transfer(<<-EOS
[dIr]
user =
EOS
))
  end

  def test_two_groups
    assert_equal('cvs chacl -R user:rwc dIr', transfer(<<-EOS
[groups]
group = user
[dIr]
@group = rwc
EOS
))
  end

  def test_collect_group
    assert_equal(['foo'], collect_group(nil, ['foo']))
    assert_equal(['foo'], collect_group({'bar' => 'foo'}, ['foo']))
    assert_equal(['foo'], collect_group({'bar' => 'foo'}, ['*']))
    assert_equal(['foo', 'bar'], collect_group(nil, ['foo', 'bar']))
  end
end

